package com.sen.ssp.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sen.common.utils.PropertiesUtils;

/**
 * Properties 配置管理器
 * @author sen
 */
public class PropertiesConfigManager implements IConfigManager {
	
	/** slf4j logger 日志记录器  */
	private static Logger LOG = LoggerFactory.getLogger(PropertiesConfigManager.class);
	
	private static Map<String, PropertiesConfigManager> managers = new HashMap<String, PropertiesConfigManager>();
	/** 存储properties文件内容 */
	private Properties content = null;
	
	private PropertiesConfigManager(String path) {
		content = PropertiesUtils.loadProperties(path);
	}

	/**
	 * 获取实例方法
	 * @param path
	 * @return
	 */
	public static PropertiesConfigManager getInstance(String path) {
		PropertiesConfigManager manager = managers.get(path);
		if (manager == null) {
			manager = new PropertiesConfigManager(path);
			managers.put(path, manager);
		}
		return manager;
	}

	/**
	 * 根据Key获得值
	 * @param key
	 * @return String
	 */
	public String getValue(String key) {
		return content == null ? "" : content.getProperty(key);
	}
	
	/**
	 * 获取配置properties文件所有内容
	 * @return
	 */
	public Properties getContent() {
		return content;
	}
}
